#include<bits/stdc++.h>
using namespace std;
int t;
int main()
{

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> t;
    while(t--)
    {
        int n,m,l,v;
        cin >> n >> m >> l >> v;
        int rd[1000005];
        int wh[100005];
        int wic[100005];
        int fv[100005];
        int jia[100005];
        int vs[100005];
        for(int i=1;i<=n;i++)
        {
            cin >> wh[i] >> fv[i] >> jia[i];
        }
        int mst=0;
        for(int i=1;i<=m;i++)
        {
            int x;
            cin >> x;
            rd[x]++;
            mst=max(mst,x);
        }
        rd[0]=0;
        for(int i=1;i<=l;i++)
        {
            rd[i]=rd[i]+rd[i-1];
        }
        int idx=mst;
        for(int i=mst;i>=1;i--)
        {
            if(rd[i]>rd[i-1])
            {
                idx=i;
                idx=i;
            }
            wic[i]=idx;
        }
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(fv[i]<=v&&jia[i]<=0)
            {
                continue;
            }
            else if(fv[i]<=v)
            {
                int st=ceil(wh[i]+(3*3-fv[i]*fv[i])/(2*jia[i]));
                if(rd[l]-rd[st-1]>0)
                {
                    cnt++;
                    vs[wic[st]]++;
                }
            }
            else if(fv[i]>v&&jia[i]>=0)
            {
                if(rd[l]-rd[wh[i]-1]>0)
                {
                    cnt++;
                    vs[wic[wh[i]]]++;
                }
            }
            else
            {
                int st=(3*3-fv[i]*fv[i])/(2*jia[i]);
                if(rd[wh[i]+st]-rd[wh[i]-1]>0)
                {
                    cnt++;
                    vs[wic[wh[i]]]++;
                }
            }
        }
        cout << cnt << ' ';
        cnt=0;
        for(int i=1;i<=l;i++)
        {
            if(vs[i])
            {
                cnt++;
            }
        }
        cout << m-cnt << endl;
    }
    return 0;
}
